Skip to content

feat: Add configurable package root for release scripts#114

Merged
konard merged 4 commits intomainfrom
issue-113-e95eec3e2b2f
Jan 10, 2026
Merged

feat: Add configurable package root for release scripts#114
konard merged 4 commits intomainfrom
issue-113-e95eec3e2b2f

Conversation

@konard
Copy link
Contributor

@konard konard commented Jan 10, 2026

Summary

This PR enhances the release scripts to support both single-language and multi-language repository structures by adding automatic package root detection.

New utility modules:

  • scripts/js-paths.mjs - JavaScript package root detection
  • scripts/rust-paths.mjs - Rust package root detection

Updated scripts:

  • scripts/version-and-commit.mjs
  • scripts/instant-version-bump.mjs
  • scripts/publish-to-npm.mjs
  • scripts/rust-version-and-commit.mjs
  • scripts/rust-collect-changelog.mjs
  • scripts/rust-get-bump-type.mjs

How It Works

The utilities automatically detect the package root:

  1. Single-language repository: Check for ./package.json or ./Cargo.toml in root
  2. Multi-language repository: Check for ./js/package.json or ./rust/Cargo.toml
  3. If neither exists, throw an error with helpful suggestions

Configuration Options

Scripts support explicit configuration via:

  • CLI arguments: --js-root <path> or --rust-root <path>
  • Environment variables: JS_ROOT or RUST_ROOT

Example Usage

# Auto-detection (default)
node scripts/version-and-commit.mjs --mode changeset

# Explicit configuration
node scripts/version-and-commit.mjs --mode changeset --js-root js

# Via environment variable
JS_ROOT=js node scripts/version-and-commit.mjs --mode changeset

Root Cause (Original Issue)

The original issue (#113) was that command-stream library's cd command calls process.chdir(), which permanently changes the working directory. This caused file operations to fail after running commands like cd js && npm run ....

This PR addresses the issue comprehensively by:

  1. ✅ Preserving and restoring the working directory after cd commands (previous fix)
  2. ✅ Adding auto-detection of package root to support both repo structures (this enhancement)

Test Plan

  • Verified syntax check passes for all modified scripts
  • Tested js-paths.mjs utility - correctly detects js/ as package root
  • Tested rust-paths.mjs utility - correctly detects rust/ as package root
  • Verify CI pipeline passes
  • Manual test in a single-language repository (optional)

Fixes #113


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #113
@konard konard self-assigned this Jan 10, 2026
The command-stream library's cd command is a virtual command that
calls process.chdir(), permanently changing the Node.js process's
working directory. This caused release scripts to fail when trying
to read ./js/package.json after running cd js && npm run ...

Root cause: After `cd js && npm run changeset:version` completed,
the process was still in the js/ directory, so reading
./js/package.json tried to access js/js/package.json which doesn't
exist.

Fixed by saving the original cwd before cd commands and restoring
it after each command that changes directory.

Also fixed publish-to-npm.mjs which was missing the cd js prefix
for npm run changeset:publish (the script is in js/package.json).

Fixes #113

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] JavaScript publish does not work fix: Restore working directory after cd commands in release scripts Jan 10, 2026
@konard konard marked this pull request as ready for review January 10, 2026 22:50
@konard
Copy link
Contributor Author

konard commented Jan 10, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.396049 USD
  • Calculated by Anthropic: $3.198203 USD
  • Difference: $-2.197846 (-40.73%)
    📎 Log file uploaded as GitHub Gist (561KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Jan 10, 2026

I think in all JavaScript related scripts we need to have configurable repository root, that will be automatically determined if not specified. We should check for repository root ./package.json and also ./js/package.json by default.

So if not in root, try to search in js folder, if that also don't exist throw an error, and suggest user to configure the root folder explicitly.

That way scripts will support both single language repository and multi language repositories.

We can also do similar thing for Rust .mjs scripts.

@konard konard marked this pull request as draft January 10, 2026 22:57
@konard
Copy link
Contributor Author

konard commented Jan 10, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-10T22:57:08.495Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

Add js-paths.mjs and rust-paths.mjs utilities that automatically detect
the package root for both single-language and multi-language repositories:

- Check for ./package.json or ./Cargo.toml first (single-language repo)
- If not found, check ./js/ or ./rust/ subfolder (multi-language repo)
- Support explicit configuration via --js-root/--rust-root CLI options
- Support environment variables JS_ROOT and RUST_ROOT

Updated scripts to use the shared utilities:
- version-and-commit.mjs
- instant-version-bump.mjs
- publish-to-npm.mjs
- rust-version-and-commit.mjs
- rust-collect-changelog.mjs
- rust-get-bump-type.mjs

This makes the scripts work seamlessly in both single-language repositories
(where package.json/Cargo.toml is in the root) and multi-language repositories
(where they are in js/ and rust/ subfolders).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title fix: Restore working directory after cd commands in release scripts feat: Add configurable package root for release scripts Jan 10, 2026
@konard konard marked this pull request as ready for review January 10, 2026 23:07
@konard
Copy link
Contributor Author

konard commented Jan 10, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.270661 USD
  • Calculated by Anthropic: $3.049357 USD
  • Difference: $-2.221304 (-42.14%)
    📎 Log file uploaded as GitHub Gist (612KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JavaScript publish does not work

1 participant